<?php

    //Listing Table Class define
    include("ClassListing.php");
	//Sub Table Class define
    include_once("ClassSub.php");
	
class LotsAndLandClass
{
    var $Listing;
    var $LotSize;
	
	function AddItemFromXML( $xmlFormat )
	{
		$Array = $xmlFormat->children();

		$this->Listing = new ListingClass;
		$this->Listing->AddItemFromXML($Array[0]);

		$this->LotSize = new AreaRoomFormatClass;
		$this->LotSize->AddItemFromXML($Array[1]);
	}
	
	function InsertSQL()
	{
		$strSqlCommand = "SELECT * FROM LotsAndLand ";
		$strSqlCommand .= " WHERE Listing_idListing = '".$this->Listing->ListingID."' ";
		$result = mysql_query($strSqlCommand);
		if( !$result )
		{
			echo $this->Listing->ListingID.$strSqlCommand." Search Failed<br/>";
		}
		if( @mysql_num_rows($result) == 0)
		{	// New
			$this->Listing->InsertSQL();
			$this->LotSize->InsertSQL();		
			
			$strSqlCommand = "INSERT INTO LotsAndLand( Listing_idListing, LotSize) ";
			$strSqlCommand .= "VALUES( '".$this->Listing->ListingID."', ";
			$strSqlCommand .= "'".$this->LotSize->ID."') ";
				
			if(!mysql_query($strSqlCommand))
			{
				//echo $this->Listing->ListingID.$strSqlCommand." Insert Failed<br/>";
			}
			$id = mysql_insert_id();

		}
		else
		{	// Modify
			$rowLand = @mysql_fetch_array($result);

			$strSqlCommand =  "UPDATE LotsAndLand SET Listing_idListing='".$this->Listing->ListingID;
			$strSqlCommand .= "', LotSize='".$this->LotSize->ID;
			$strSqlCommand .= "' WHERE idLotsAndLand = ".$rowLand["idLotsAndLand"];
			if(!mysql_query($strSqlCommand))
			{
				echo $this->Listing->ListingID. $strSqlCommand." Modify Failed<br/>";
			}
			
			$this->Listing->ModifySQL(  );
			$this->LotSize->ModifySQL( $rowLand["idLotsAndLand"] );
		}
	}
}

?>